//
// Created by shubo on 2020/2/5.
//

#include <iostream>
#include "ut_dict.h"

struct my_key : public dict_key_base {

    int data ;

    virtual uint32_t hash() const override {
        return this->data;
    }
    virtual dict_key_base* dup() override{
        auto another = (my_key*)malloc(sizeof(my_key));
        another->data = this->data;
        return another;
    }
    virtual int compare(const dict_key_base *key2) const override{
        auto another = (my_key*)(key2);
        return this->data > another->data ? 1 : 0;
    }
    virtual void release() override{
        free(this);
    }
};

struct my_value: public dict_value_base {
    int data;

    virtual dict_value_base* dup() override {
        auto another = (my_value*)malloc(sizeof(my_value));
        another->data = this->data;
        return another;
    }
    virtual void release() override {
        free(this);
    }
};

int main() {

    auto dict = dict_plus<my_key*,my_value*>::create(64);

    my_key key;
    key.data = 0;
    my_value value;
    value.data = 0;

    for(int i = 0; i < 100; i++) {
        key.data = key.data + i;
        dict->add(&key, &value);
    }
    auto iter = dict->get_iterator();
    auto entry = iter->next();
    while (entry != NULL) {

        //std::cout<< entry->get_key()->data << " : " << entry->get_value()->data << "" << std::endl;

        entry = iter->next();
    }

    return 0;
}